package com.xt.LibaryDeskManager.job;

import com.xt.LibaryDeskManager.service.SelectSeatService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Calendar;

/**
 * 每天7点，12点，22点执行任务
 */
@Component("SelectSeatJob")
public class SelectSeatJob implements Job {
    @Autowired
    private SelectSeatService selectSeatService;

    private static final int S1 = 7; //上午7点
    private static final int S2 = 12; //中午12点
    private static final int S3 = 22; //下午22点
    private static String DateVlue=null;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        Calendar calendar = Calendar.getInstance();
        if (calendar.get(Calendar.MONTH)<9){
            DateVlue=String.valueOf(calendar.get(Calendar.YEAR))+"-0"+String.valueOf(calendar.get(Calendar.MONTH)+1)+"-"+String.valueOf(calendar.get(Calendar.DATE));
        }else{
            DateVlue=String.valueOf(calendar.get(Calendar.YEAR))+"-"+String.valueOf(calendar.get(Calendar.MONTH)+1)+"-"+String.valueOf(calendar.get(Calendar.DATE));
        }
        try{
        if (S1 ==calendar.get(Calendar.HOUR_OF_DAY)) {
            selectSeatService.updateSelectSeat(DateVlue,1,1,2);
        }else if(S2==calendar.get(Calendar.HOUR_OF_DAY)){
            selectSeatService.updateSelectSeat(DateVlue,1,2,3);
            selectSeatService.updateSelectSeat(DateVlue,2,1,2);
        }else if(S3==calendar.get(Calendar.HOUR_OF_DAY)){
            selectSeatService.updateSelectSeat(DateVlue,2,2,3);
        }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
